Removed commented lines
Optimized loop over j1
Changed function signatures to allow more general observation vectors
Use a lookup table for the states to avoid recomputing