made some major amendments and tidied scripts