Improve before
and after
internal logic
#537
Merged
before
and after
internal logic
#537