Refactor to use twdb library