fix for potential encoding issue
Fixed closing resource