General tidying, removal of unused functions and some type changes to make splint happier.