optimizing writeLog