added leave function (not completed)