moved state logic from controller to model