Update to lab5.c

Refinements to gains and algorithms.