small refactoring of handling before/after blocks and also add missing docstrings