Added SQL code, some other minor changes in shell