More robust handling of kernel compilation errors; fixed a bug with the 'cleanup' flag