Fixes warnings + potential memory leak