refactoring and tweaking