Too much file handles opened system error fixed.

Hello. I spend some time on several improvements. Hope you'll merge them. It's my first triage of Github, so if you have any notices regarding process of git oriented stuff, just let me know. Thanks.