replacing "for" with Seq functions