Changing scope of unique var counter to ensure uniqueness