Rspec unit tests passed and code refactoring