minor optimization and corrected comments