refactoring and pythonization