refactor and pass rubocop