Various fixes to script