Refactored for Swift beta 4 compatibility