Sort:  

The error is logical, the problem is that it is not readable unless you know how to read code...