Fix a few leaks and remove some type parameters

Only commits starting from 7ce6bb8 are relevant