Fixed bugs in SQL, format() string. Also indented docstring.