Code tidy to remove warnings and use generics