refactor: extact method writePreamble