Swiftifying the existing code