minor simplification and cleanup of duplicate code