Set of small refactoring and fixes

While debugging of XBMC I found some points that need enhancement.
So here is my set on commits.