Version with sqlite base & optimize method