Removed some ugly duplicate code