Added beforeeach function for controllers