Refactor this giant piece of turd.