moved the functions to the top of the file