Changed in controllers and reduce number of lines by defining functions