fixed some ugly code