algorithm bug