Fixed some issues that cause crashes

The rest of the scripts need to be modified, I don't have time to do
them all.