fix bogus errors caused by wrong variable name
make init scripot more generic
increase error checking