Fix some memory issues (see #2 for the remaining one)