code refactor for osx-window