Change newInstance to a generic method