Make tasky runout of the box by fixing sql reference

Also added some suggested code clean up :-)