Code cleanup, PSR-0, and make into Beagle