format fixed, substr changed to mb_substr, database-related settings added