Unit tests for new code upto mid term.

Signed-off-by: Ashutosh Dhundhara <ashutoshdhundhara@yahoo.com>

Fix coding style and code duplication.

Signed-off-by: Ashutosh Dhundhara <ashutoshdhundhara@yahoo.com>

Code refactor.

Signed-off-by: Ashutosh Dhundhara <ashutoshdhundhara@yahoo.com>