implemented foreach with parallel option