Refactored and added rspec tests