fix a hard-coded version in the build script
fixed unscoped vars, cleaned up some code.