Define functions before they are used