Added comments, remove syntax error and add try except block