Bug fixes and conversion to printf-style