should be abstracted into more functions. haven't fully thought it through yet but it's messy right now and not easy to change.