Fixing a number of issues around failed builds

Check a Directory Exists before trying to delete it in rmdir()
Check that the build directory exists before continuing in a number of places.