Added SQL elements, tidying the rest