Some fixes/cleanup as I tried to use this in direwolf.