added fix for function hoisting