Moved code around to make it cleaner and added writing function for
weekly analysis.