Adding optional logging for debugging.