added test_ad.py and fixed some bugs