Fixed some encoding bug by setting sqlite text_factory to str.
Refactored code in dbmanager and insert frontier links into the DB in batches.