-Added exception handling for scripts.
-Some code improvements