making progress, but code is starting to look sorta frankenstein monstery