adding lots and lots and lots of logic for something that seems like it should be lots and lots and lots simpler