Refactored for xcode/swift beta 4