code modified as per MVC rules