Debug and bugfixes