Improve build file, and tweak error handling.