Lots of small tweaks and inline documenting