cleaned up merging functionality