Update build script to keep file permissions
Update script and minor errors