improved quarry algorithms, fix #1577