improved apply procedure able to call with variable length arguments