refactors helper code to models.