implemented node trimming in python