Fixed calling functions before they are defined