try not to segfault in assorted spots; catch errors & throw exceptions.
several fprintf's now moved inside of #if defined(DEBUG)... statements.