incremental work on porting to ATS2: main loop and libats