fix a few refactoring bugs