added some comments and corrected a return statement