Clean up some ugly code