Use proper scope on openDB and proper valid check