Improved X11 API implementation