Refactor core.py.

- Rename page and thread to page_json and thread_json for better clarity.
- Extract thread matching code into thread_matches(...).