minor cleanup of build.sh
fixed threads and minor refactoring