Lda implementation code