Move functionality to model to allow api use