Added more logic regarding leaving nodes. Issue #30.

- Original issue seems to be fixed. Needs testing.