Fix some ugly code