First working version using X events