Improve generic constraints

This makes the interfaces more useful without require ugly casts.