Convert most AnyObject to Generic <T>

In order to not lose type information many methods have been changed to use generics instead of AnyObject.