moved functions to the top