Rewrite using streams