move the code to controller