refactoring, fixing bugs