Should be nicely overengineered now
seems to work