I don't see any obvious problems. Are there any exceptions being thrown at runtime? I mention this because if I strip it down to bare essentials it works for me

try {
...