remove nonlocal keyword for compatibility with python2.7.x