Fix variable scoping bug through arguments passing through function