caps: improve caps handling

Avoid caps copy and leaks
20 files changed