Adds depth field to fix the ordering issues with ancestors. Closes #52.