Add test coverage

This update adds test coverage, and fixes a memory leak in the heartbeat module that prevented the test suite from exiting correctly.