Although this is much better than the old version, this doesn't handle some edge cases like a very harsh diagonal.