This is just code copied over from `views/main.py`.