fixed some encoding and chunk bugs