Adding the sort algorithm, needs a little debugging