added events, made code more independent