Some minor fixes and improvements.

File matching code might cause trouble if highly popular: race appear conditions.
Merge pull request #1 from tomayac/patch-1

Some minor fixes and improvements.