some clean up and refactoring