Made the code dry and changed rspec accordingly