Moved functions into the correct scope