implemented leave functionality