refactored main.js / added leave functionality