fixed segfaults; decoding implemented