Removed some duplication and made some helpers