Fix nil variable in after function