some tweaks and refactorings