added multinomial logit; eliminated cycles; other refactoring and cleanup