cleaning up and fix decode_free