add error checking, fix missing dependencies, cleanup of var warnings