rewrite to use local database