checked and corrected code