Added SQL stuff from Frank