Fixed calculating of script/function local counts.