Refactoring and tweaking