added depth loop