Changed window reference to $window