holy shit refactored the fuck out of it