Updated MacOSX code, worked on window events