Use atexit to make tidying up at exit time neater
Behave correctly when no data present. Closes #12