moved code to controller