I was quite unsure this would be correct, but didn't think about adding the Init/Finalize functions in X_clear_globals / X_close