refactorings in core.py