huge refactoring of spatialite parts plus cleanups
minor cleanups