Adding rspec tests and fixing a few bugs