refactoring of the function check_occurrence
implementing the algorithm
implementing the standard version
some commented lines were removed
an error condition fixed and the constructions of intervals changed to a more friendly way