Used RAII to protect against memory leaks