Refactored and debugged whitening.