Refactor domain parsing