Refactoring core.py