|#723| reformatting sql and  controller