Use generics

Fixes #29