how to write end behavior