bump version to 4.0; refactor build scripts