adding sorting to tree