fix indexing bug in decoder