Split some code to controller