Remove exceptions, rewrite logging, fix a few bugs