Unit tests fixes

A bunch of unit tests fixes.
The fixes are tested on CentOS 6.5 and Ubuntu 12.04.