Refactor code and save finished dataset flag to reduce later load time