a few more refactorings, slightly faster
merge