fixed memory leaks in python interface, perf improvments in selection records