Making script more stable