Final version of controller code.