the ugliest code, but feels so much saner