simplify js code