Fix a database connect issue, fixed sorting