refined the code to pass rubocop checks