Condense and refactored

There is now absolutely zero code that is repeated. To the best of my ability, the code has been as condensed as possible while still maintaining a high level of readability.