Last stable version of the getToken function