Rubocop corrections and refactoring