replaced global function to local