Refactored out every condition to its own method to make the code more readable.