cleaned up controller code