move writing to separate class