Working lda function