rewritten to use Swift 1.0 features