divide js code in functions