Swap global function for closure

Change-Id: Iddf9cf670a7eda431a0defc24c2f993a537ca18e