Fix bug by ignoring depth in purify function