added optional logging instead of console