Script cleanups

Cleaned up some scripts so that they are:
- a bit safer
- better formatted
- cleaning up after themselves