further improvements on rspec tests and code refactor