Internal cleanup and reorganization. Added function documentation.
Internal cleanup. Added function documentation. Changed debug output format.
Internal cleanup. Updated function documentation. Debug output reformatted.