refactoring, bug fixing