Reduce scope of local variables

Signed-off-by: Sup Yut Sum <ch3cooli@gmail.com>