refactoring everything into python