better events handling + refactor