rewrite merge check to be more effective