Updated js function