Corrected version based on class discussion