moved the logics away from the controller which is good

moved it to controller which isnt that good