Completed Thomas's function homework