Code cleanup and some adaptations to the chunk approach