Some bug fixes and doc fix