Maybe make $t_parent_id = false to start with, to simplify the if/else logic?