Bunch of refinements and bug fixes.