Added documentation and debug statements.