It seems like this should be able to be done in a way that's easier to read/understand.