add before and after functions