some minor refactoring and code cleaning