Minor restructure, moved primes function to an include file since it repeated 3 times