Cleaned up some ugly code.