Move and separate response handling out of request function

Move and separate response handling out of request function