Splitted actual writing to a new function.