fixed bug, refactoring