added depth check