Correction to js function