some code cleanup, formatting and documentation.