Fixes unused var and avoid reassigning keys

Changed code so key doesn't get reassigned in loop
Made use of filtr variable