master: chunks: refactor and fix state updates