Workaround for weird close() behavior. This needs more investigation.