Fixing bugs, cleaning and reorganizing scripts