Clean up some spaghetti and unused code.