better prime function