adding better detection of objects leaving window