get rid of more mallocs, and more raii