Fixing up rspec tests and related bugfixes