Fixed flagging script

Hi,

I have fixed the small hiccups in the code, hope it will work just fine now.