solving habitat merge problem.