fixed a couple of bugs and almost have decode working