The if block is not required. Instead refactor the add method to add method to insert child at correct index