more attempts at sorting logic