Fixes refactoring bugs