fixed sorting, addressing other issues