Efficient table-lookup implementation

Using pd-style fast table lookup.