restructured logging code