Reorganize core.py