use RAII for resource management