SQUASHME: refactor into functions
SQUASHME: refactor some more
WIP