moving merge error checking earlier