Fixing bugs introduced from refactoring