polish seeking code & fix memory leaks