this code is dying to be refactored, but holy fuck i think i did it