Refactored the piss out of this mother F-er