bugfixes, clean ups and corrections