Refactor Cocoa graphics code