adapted code for even easier context porting and added X11 context code