improved performance somewhat, algorithm aborts as soon as it finds a factor