some cleaning and refactoring