Massive bugfixes