Cleaned code, fixed script npe if no scripts were running.