added some documentation and code comments