Fixed a bug on context close