You flickering problem is really strange since it seems you really use FLIP only one time in the whole program, as well as SETBUFFER.
you may try to replace
FLIP
by
VWAIT:FLIP 0
and see it it helps
you may try to replace
FLIP
by
VWAIT:FLIP 0
and see it it helps