Refactor to run in both Python 2.7 and Python 3.6. This is important as
python 2.7 is end of life.
I tried to edit as few things as possible in this commit to minimize
conflicts which means the code could be prettier.
Signed-off-by: Viktor Sjölind <viktor@sjolind.se>