lots of cleanup, fixed reporting bugs, improved error handling, minor optimizations