fixed ref-count bug in try-except handling