Fix bug in decode and add tests
Merge pull request #1 from ttacon/master

Fix bug in decode and add tests