shuffling functions around to avoid circular dependencies.