Added in-memory performance test, and a few optimazations