improved logging code