improved merge routine, add test code
rspec for future ruby implementation