integrate Hai's code with Ellen's