some minor refactoring for readability