Refactored domain parsing algorithm