Added rspec tests; bugfixes