changed prime factorization method to be tail recursive; added full reference to source