Adapted for Swift