improved build script so that it can also clean the output directories