Improving str2Dom function