after hour and hour, finally sort planning. really not proud about sort but ... it works