further improvements on rspec tests and refactoring of code