Make writer global + code cleanup