Close #4

Tested properly.  Simplify code.
better to_dict function