Optimized db lookup (#10), still need some tests