Made various improvements and fixes to scripts