Created method instead of view code in controller