Print environment on debug + fix some memory leaks