Working version with connected database