updated code from mac