Merge "More bug fix and refactoring"