Fixed some database querys