Fixed function to use parameter instead of program global.