Use parameterised generics.

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
Use atom iterator instead of indices.

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>