minor refactoring and code cleaning