changed algorithm to make it look into children a little better