Fix indentation and error handling