Unit tests improvement + minor refactoring.