function divideIntoDayFiles (aggregatedMinChunks) {
                        try { 
                            // now that we have aggregated min chunks, loop through them placing them into day files 
                            let lastSavedFile
                            let files = [] 
                            let heartBeatCounter = 0                   
                                 
                            // Load data from the last day file if needed
                            if (mustLoadRawData) {
                                mustLoadRawData = false
                                let startingDate = new Date(initialProcessTimestamp)
                                let currentTimestamp = new Date(aggregatedMinChunks[0][0])
                                    
                                // Check if the day of the last day file overlaps with the day of our new min chunk
                                if (checkIfOnSameDay(startingDate, currentTimestamp)) { 
                                    // If it does we load the old day file before adding our new data to it
                                    let fileName = "Data.json"
                                    let filePath = getFilePath(initialProcessTimestamp, DATA_FOLDER_NAME)
                                    let fullFileName = filePath + '/' + fileName;
                                    let fullFilePath = global.env.PATH_TO_DATA_STORAGE + '/' + fullFileName;
                                    console.log(fullFilePath);

                                    if (SA.nodeModules.fs.existsSync(fullFilePath)) {
                                        // If it does we load it and start the sorting process
                                        SA.logger.info(MODULE_NAME + " processAndSaveMessages - > divideIntoDayFiles -> loading last saved file from file = " + fullFileName)
                                        lastSavedFile = JSON.parse(SA.nodeModules.fs.readFileSync(fullFilePath, 'utf8'))
                                        files = sortIntoDays(aggregatedMinChunks, lastSavedFile)
                                        
                                    } else {
                                        // Fall back to sorting into days without the old file data
                                        SA.logger.warn(MODULE_NAME + " processAndSaveMessages -> divideIntoDayFiles -> old file not found continuing without previous data tried to find file = " + fullFileName)
                                        files = sortIntoDays(aggregatedMinChunks, undefined) 
                                    }
                                } else {
                                    // old file not needed to process this data since it is not on the same day
                                    SA.logger.info(MODULE_NAME + " processAndSaveMessages -> divideIntoDayFiles -> starting new day file to save data")
                                    files = sortIntoDays(aggregatedMinChunks, undefined) 
                                }
                            } else {
                                SA.logger.info(MODULE_NAME + " processAndSaveMessages -> divideIntoDayFiles -> starting new day file to save data")
                                files = sortIntoDays(aggregatedMinChunks, undefined)  
                            }

                            return files
                            
                            /**
                             * The function sorts data into day files based on timestamps.
                             * @param newMinChunks - an array of one minute chunks (each represented as an
                             * array with at least three elements: start timestamp, end timestamps, and data values) that need to be
                             * sorted into day files.
                             * @param oldMinChunks - an array of one minute chunks coming from a previously saved day
                             * file
                             * @returns an array of day files, where each day file is an array of
                             * minChunks.
                             */
                            function sortIntoDays(newMinChunks, oldMinChunks) {
                                let currentDay = []
                                let dayFiles = []
                                let chunksToSort = []
                                
                                // TODO: refactor boths side of the main logic switch to use the same core sorting logic via a function
                                // if we have an old day file to start from we first figure out where our new data begins in regards to the old data
                                if (oldMinChunks != undefined) {
                                    // merge the old minChunks with new minChunks to create the most complete day
                                    [currentDay, chunksToSort] = mergeChunks(newMinChunks, oldMinChunks)
                                    dayFiles.push(currentDay)
                                    currentDay = []

                                    SA.logger.info(MODULE_NAME + ' Sorting into Day files. Current file count: ' + dayFiles.length)
                                    TS.projects.foundations.functionLibraries.processFunctions.processHeartBeat(processIndex,  'Sorting into Day files. Current file count: ' + dayFiles.length)                           
                   
                                    if (chunksToSort != undefined) {
                                        // sort remaining chunks into day files
                                        for (let minChunk of chunksToSort) { 
                                            if (currentDay.length > 0) {
                                                // check if chunk still in current day
                                                let lastChunk = currentDay[currentDay.length - 1]
                                                let lastChunkEnd = new Date(lastChunk[1])
                                                let currentChunkBegin = new Date(minChunk[0])
                                                if (checkIfOnSameDay(lastChunkEnd, currentChunkBegin)) {
                                                    // if so add them to the same day
                                                    currentDay.push(minChunk) 
                                                } else {
                                                    // if not save the current day file and continue to the next
                                                    dayFiles.push(currentDay)
                                                    currentDay = []
                                                    currentDay.push(minChunk)

                                                    SA.logger.info(MODULE_NAME + ' Sorting into Day files. Current file count: ' + dayFiles.length)
                                                    TS.projects.foundations.functionLibraries.processFunctions.processHeartBeat(processIndex,  'Sorting into Day files. Current file count: ' + dayFiles.length)                          
                                                }
                                            } else {
                                                currentDay.push(minChunk)
                                            }
                                        }

                                        dayFiles.push(currentDay) 

                                        SA.logger.info(MODULE_NAME + ' Sorting into Day files. Current file count: ' + dayFiles.length)
                                        TS.projects.foundations.functionLibraries.processFunctions.processHeartBeat(processIndex,  'Sorting into Day files. Current file count: ' + dayFiles.length)                          
                                    }

                                    return dayFiles
                                } else {
                                    // Else we need to start fresh and sort into day files
                                    for (let minChunk of newMinChunks) { 
                                        if (currentDay.length > 0) {
                                            // check if chunk still in current day
                                            let lastChunk = currentDay[currentDay.length - 1]
                                            let lastChunkEnd = new Date(lastChunk[1])
                                            let currentChunkBegin = new Date(minChunk[0])
                                            if (checkIfOnSameDay(lastChunkEnd, currentChunkBegin)) {
                                                // if so add them to the same day
                                                currentDay.push(minChunk)
                                            } else {
                                                // if not save the current day file and continue to the next
                                                dayFiles.push(currentDay)
                                                currentDay = []
                                                currentDay.push(minChunk)

                                                SA.logger.info(MODULE_NAME + ' Sorting into Day files. Current file count: ' + dayFiles.length)
                                                TS.projects.foundations.functionLibraries.processFunctions.processHeartBeat(processIndex,  'Sorting into Day files. Current file count: ' + dayFiles.length)                          
                                            }
                                        } else {
                                            currentDay.push(minChunk)
                                        }
                                    }

                                    dayFiles.push(currentDay)

                                    SA.logger.info(MODULE_NAME + ' Sorting into Day files. Current file count: ' + dayFiles.length)
                                    TS.projects.foundations.functionLibraries.processFunctions.processHeartBeat(processIndex,  'Sorting into Day files. Current file count: ' + dayFiles.length)                          
    
                                    return dayFiles
                                }
                            }

                            /**
                             * The function merges new chunks of data with old chunks of data based on
                             * their timestamps.
                             * @param newChunks - An array of new chunks to be merged with the old
                             * chunks.
                             * @param oldChunks - An array of arrays representing one minute time intervals
                             * (chunks). Each inner array has at least three elements: the start
                             * time, end time, and data values of the chunk.
                             * @returns an array with two elements: the first element is the current
                             * day file (an array of chunks), and the second element is either an array
                             * of chunks that come after the current day or undefined if all chunks are
                             * on the same day.
                             */
                            function mergeChunks(newChunks, oldChunks) {
                                let currentDayFile = oldChunks
                                let chunksAfterCurrentDay

                                let lastChunk = oldChunks[oldChunks.length - 1]
                                let lastChunkBegin = new Date(lastChunk[0])
                                let lastChunkEnd = new Date(lastChunk[1])

                                let firstNewChunk = newChunks[0]
                                let firstNewChunkBegin = new Date(firstNewChunk[0]) 
                                let firstNewChunkEnd = new Date(firstNewChunk[1])

                                if (firstNewChunkBegin.getTime() ===  lastChunkBegin.getTime() &&
                                    firstNewChunkEnd.getTime() === lastChunkEnd.getTime()) {
                                        // Replace last min chunk with newly aggregated one
                                        currentDayFile.splice(-1, 1, firstNewChunk)
                                        newChunks.shift()
                                } 

                                for (let i = 0; i < newChunks.length; i++) {
                                    let currentChunk = newChunks[i]
                                    let currentChunkBegin = new Date(currentChunk[0])
                                    if (checkIfOnSameDay(lastChunkEnd, currentChunkBegin)) {
                                        currentDayFile.push(newChunks[i])
                                    } else {
                                        //TODO: test this branch
                                        chunksAfterCurrentDay = newChunks.slice(i)
                                        return [currentDayFile, chunksAfterCurrentDay]
                                    }
                                }

                                //If all chunks are on the same day then we will return the current day file and leave the chunks to sort as undefined
                                return [currentDayFile, undefined] 
                            }

                        } catch (err) {
                            TS.projects.foundations.globals.processVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).UNEXPECTED_ERROR = err
                            TS.projects.foundations.globals.loggerVariables.VARIABLES_BY_PROCESS_INDEX_MAP.get(processIndex).BOT_MAIN_LOOP_LOGGER_MODULE_OBJECT.write(MODULE_NAME,
                                "[ERROR] start -> saveOHLCVs -> err = " + err.stack);
                            callBackFunction(TS.projects.foundations.globals.standardResponses.DEFAULT_FAIL_RESPONSE);
                        }  
                    }
The function divides aggregated minute chunks into day files based on timestamps
and merges them with previously saved day files if necessary.
@param aggregatedMinChunks - An array of one minute chunks (each represented as
an array with at least three elements: start timestamp, end timestamps, and data
values) that need to be sorted into day files.
@returns The function `divideIntoDayFiles` returns an array of day files, where
each day file is an array of minChunks.