Some useless functions was removed. Correct processing of cases, when function can't count number of pages, was added (not tested)