clean up build script.
Some refactorings.

(refucktorings?)