Filling and querying the database