fix bug and check for nil domain