Core/Scripts: Fixed uninitialized variable and memory leaks