fix a vector bounds bug, and improve performance of merge