this is some ugly code...