Refactor build

I've finished the new build.
Still some things to do better, but the current is really a mess.

@contra