Fixed some resource leakage