Changing N cut-off to Tolerance judgement.
Change the pmode iteration loop from file reading to generation within the subrountines, in order to improve the speed further