Add getChunks(), printError(), replace while loop with for loop, and make comments more descriptive.