bugfixes from Mat