Shouldn't this be moved to the beginning of the function?