sophia: refactor log writer; optimize single stmt case