use raii where appropriate