Made some scripts more robusts