Script adapted to the Timeout option of mist. During the implementation of this feature I found and fixed some bugs on the script