optimizing the PFSS routine to reduce space and running time