cleaned up to match what I've done in profile_egcd.py.