Refactorized and add chunk_size