refactor the bit about skipping the last chunk