Move global function to local scope