Updated codes to support older database queries