debugged automation code