Added back basic sorting on insertion. Bug fixes