Scripts: Random script fixes and code optimizations