add try catch and fix indentation