Simplify js code