more refactor to avoid circular imports