Added comments and corrected isValid function in class 'rules'.