fixed some ugly code.