wrote most of main function for A.py