Simplify code and fix py2.7 special case

This code now works on both python versions.

Signed-off-by: Christoph Kassen <c.kassen@telekom.de>