Added Try/Except/Finally, fixed output issue