Fix some bugfixes (thanks Klas)