Cleaned up the controller code