fix resources leaks