various opitmizations to pca fn