added handleEvents to server loop