minor tweaks and refactoring