refactor base.php: further reduce duplication