extracted contacts db logic from main worker script