Thanks a lot for your answers. Now I'm using the "optimized" version Steven Taschuk sent. (Performance is critical at the moment). I'm grateful for all your code and thoughts, -- Michal Kurowski <mkur at poczta.gazeta.pl>