Clean and update build output more intelligently

Fixes #183.
this needs a better name - getCommonSourceContainer()