edited js function and remove third instantiation