added support for beforeeach and aftereach