small refactoring and performance improvement