Added rspec tests and fixed two bugs