Tidying up L-function code and bug fixes from Fredrik S.

Includes bug fixes by Fredrik and mainly trivial changes to clean up L-function code and updating L-function tests.