Initial copy of Cocoa implementation from Dream.