refactor slightly to DRY