tail merging shrinks this code a bit. Could do more in future.