Performance improvements and chunk flipping fixed