ugggh... the prime function looks awful, but it works.