moved some logic from view to model