Defer prepared command deallocation if needed

Fixes #416