Use cleaner way to attach memory DB for search in core.py.
Improve performance of search in core.py. Profiling code still there.