I can't remember if there needs to be a space in there or not may be order by rather than orderby but in any case that will make sure that the last record is the highest block number which from what you have said is what you want and not what you are getting so that should be the solution.

As for the code in red I can't tell much about it. What you really should do is set a break point and step through the code line by line to see what it is doing and check the values of your BK and CN vars to see if they are correct when the program is running.