Fixed script locking up when shutting down