Converted remainder of logic to work through the writer