Implemented callbacks to take out duplicate code and reformatted some if statements

Refactoring is boring, but necessary.