Rewrite in Swift