Fixes to buffer allocation and device shutdown