reorder code to call free() just before function exit
add quirk setup code
add handling of XCloseDisplay quirk