Code cleanup

Hello Magnus,

In this PR I'm going to perform a partial code cleanup.
It is in progress now...

Signed-off-by: Oleg Nenashev