Bug fixes and refinements