Implementation for q4 (correct).