Bugfixes after input from Thomas Greil, thank you very much :)