various bug fixes to scripts