move code from router to controllers