updated autogather code