refactored with let and added count of parents to check merge