Code cleanups, more error logging, header file fixes