restructure of sub functions to be prototype methods