Fixed a few bugs. Formatted the code correctly. Dropped PHP4 conventions. Simplified code and usage.