refactor to better object oriented style and DRYer tests