Added much needed changes to the AP class, and cleaned up main a bit.