replaced algorithm to join json and added sorting