Cleaned up controller code