code refactoring, bug fix