Restructured the SqlEngine. Not yet finished (see "TODO" in the code).