Cleaned up the code some more with help from Rubocop.