Fixed bug in refactoring
Fixed logic flaw in refactoring
Reformatting code