improve the externals system and move all the external.* functions to it