Fixed up boolean logic, started refactoring redundant code