Better error handling in rebuild