Improve error handling in init code