a bit of code cleanup
Found another bug in refactoring
Refactoring bug fix