Build improvements

Quite a significant selection of build improvements - pretty close to a full rewrite actually