cleanup, fixed refactoring bugs