Added count_children function