Cleaned up multinomial code