simplify js function