put this at the beginning of the function