Modified prime function