Port over controller logic from Python.