added rspec test
changed some parts of the implementation