Refactored to work in 8.1 and Xcode 61