refactored logic in controller method to get stats