Ported to Swift.