Better error handling
Fixed indenting