Removed more duplication, and weird coding style