some fix and refactoring