Refactor, test, and enable buffer cleanup tasks.

Fixes issue #4