added beforeRequest and afterResponse callbacks
upped version