Tidy up some nested cases and add more blank lines and some comments.