Fixed the chunk creation function