Create main database loop