fixed memory leak; added documentation.