modified prime function