added optional logging