Changed foldM_ to mapM_ (thanks to relrod)