Further refinements and refactoring