replaced global function with an appropriate object