Some bug fixes and some extensions