moved controller code to model