restructured code for autotest