Clean up a few bits of mind-blowingly ugly code