Fix a pretty poor, old and neglected file.
Another pretty nasty file now looks nicer
Hatrick of rewrites.