Refactoring out some logic faults