extract commands in function instead of variables