Clean the code to pass pyflakes checks

Remove unused imports and variables
due to pyflakes complains in order to be able
to reenable it in the stardard build process

Change-Id: Ia2d26c15ffb15ce3d4c112d2cbf2bafe105fe0de
Signed-off-by: Simone Tiraboschi <stirabos@redhat.com>
Refactor to improve code readability

Refactor the code to improve readability
splitting a very long method into 4, easier, methods.

Change-Id: Ib2e9fbdacaed5ee6bc17bee50abc36a2f49dd496
Signed-off-by: Simone Tiraboschi <stirabos@redhat.com>