Fixes bugs introduced with code refactoring