Memory leak fixes ,and script manager