Improved type name resolution

1) Now removes const& from types
2) If a typedef is used, keep using it as is
3) Correctly build template types