Bug 199v2

This is the second version of pull request, which fix #199 and is big step for #255 .
It includes recommendations from karolherbst.

P.S. Please someone beside me test it before merging.
P.S.2 After merging do not forget to inform Gentoo guys about build changes.