add documentation and code cleanup