Some minor fixes and improvements.

File matching code might cause trouble if highly popular: race appear conditions.