Refactors code to get last child treema