made extensive changes based on rubocop results