misc clean up and refactorings