Adding apple's code