I tried to avoid the "local variable used before assignment" exception here, but your solution is definitely much more elegant !