Various bug fixes, refinements