improved NWCorner algorithm