moved auto commands inside if block