Separate writeDuty and writePeriod into their own functions.