Minor bugfixes supplied by nuno.