Script fixes and a little bit of cleanup