updated event handler, still not working properly