Fixed function scoping issue