some minor fix and refactoring