decent rebuild of build function to make it more efficient and provide a...

...ccurate ordering of sync tasks