wrap code in closure

Signed-off-by: Connie <cleung334@gmail.com>