Improve queue free-on-delete functionality.
Also add unit tests.