Organized the code in a function instead of a script.