Refactoring from pycompilation