update beforeReply and afterReply; for middleware usage; ref #6

see issue #6