added documentation and code cleanup