Various bugfixes & improvements