Updated function replacement to order variables which must are added