Updated some of the sql code.