minor refactoring to avoid repeated code