I think you might benefit from reading
How (Not) To Ask A Question. While I can say that the syntax in your code snippet seems reasonable, it's impossible to replicate your behavior with the very small sample you've provided. As well, you say "it fails", but it is unclear what that means in this context. Does the code fail to compile? Does it just not reproduce the behavior you expect? What behavior do you expect?
Please post additional code (wrapped in <code> tags - Writeup Formatting Tips). If possible, make as short as you can, but a monk who wants to help should be able to just download it, run it and see the behavior you are having trouble with.