Add delegate

And clean up some log code