refactoring since I can't figure out what the f*** is going on here