added documentation and an initial try on error handling
(the old rrd style, but with thread local variables)