added documentation and corrected mistakes