format the code and add function to deal with response