fixing bugs, refactoring