Added some hacks to make generics work properly