i used to have a lot of tiny flies - look like midges when i opened the tank lid , mine are living in the top of my juwel filter
i asked my lfs and they said to look into live feeding of blood worms and they can live in your filter if they get in there and hatch into the small flies/gnats - i found this on a website (http

/www.newton.dep.anl.gov/natbltn/500-599/nb529.htm)
so the lfs said either dont buy any live bloodworm or plants cos thats the only way you can guarentee never having some small flies
to help get rid of mine i put an extra filter on the tank - waited til it was completely cycled and then started rinsing the media from the main filter in used tank water every 2 weeks for a few months now i would say i have one or 2 flies every so often and thats it - and i still feed live bloodworm but havent introduced any new plants for a while i now cultivate from my own so i dont introduce any more critters
excert from website
Dozens or even hundreds of species of them breed in
fresh water where both the adults and their larvae are a major source of
food for almost all kinds of fish. Mature larvae of the different kinds
range from a tenth of an inch to over an inch in length and, in color,
may be white, yellowish, greenish, bluish, pinkish, or very deep red.
The last, known as the "Blood Worm," is collected and sold in pet
shops to feed aquarium fish. It thrives in moderately polluted water.
thanks sarah xx