sorting logic working version 0.1