fix some ugly code