Add rspec tests for modules;
minor changes in code resulted from the tests;
clean up test helper and redundant test code