fix bug, refactoring