Slight code refactoring.

AFDP-111
Added unit tests.

AFDP-111