Rework logic to be more sonar-friendly

Change-Id: I91316a11bab8a9bcdd0c5a65d66be1fac2ec66fd
Signed-off-by: Robert Varga <rovarga@cisco.com>
Increase unit test coverage

Change-Id: I79aa200649e4cdee4c3a960a350cb1f21ad0d4f2
Signed-off-by: Robert Varga <rovarga@cisco.com>