Implemented manual locking for the DB because sqlite3 in Jim lacks any.