After a few hours of testing find the source: I had some IFNDEFs in my script. But they had nothing to do with that functions above. I remove them and now it works....strange...