Swap global functions for closures

Change-Id: Ib811d11a58621d14c0549b5a97b7f735fd3addab