Memory leak fix; minor improvements.