Refactor: apply api.internal namespace, move helpers.