Restructure and convert to Python 3