better generic index building and seeking code