Fixed bugs in ViCriteria and updated SQL