Bugs fixes and doc cleanup