Fixed bug in refactoring. Tests pass.