Refactored class and added rspec tests