corrected error in sql, fixed layout output