refactor in functions to get domain and user