Reworked main to have two writing functions instead.