replace plain function with constructor and protoype