This method was refactored to clear up duplication of logic and increase readibility of the code.