fixed issue with going out of bounds on last chunk