Clean up some spaghetti code.