Working LDA function