change function expression to function declaration to prevent function hoisting issue