massive refactor holy shit