Fix variable scope

The previous code works but it is not good manner. It just works
accidentally.

Local variable defined in block can't be accessable out of the block.

In this case, "result" can be used because other "when" clause has the
same name local variable is defined.