added depth limit of 50, to keep it from getting stuck