Remove unused code, fix handle leak.