Reorganize ata code; reduce stack usage.