problem with writeln (or program bug?)