Add rspec test and refactor