Refactored to pass rubocop