added calculation of principal component directions, corrected minor mistakes