Fixing order of function declaration in js.