refactoring some ugly