lda and sta rewritten