fixed the next script function