Added SQL export
Various bugfixes