completely refactored PCA fn