improved sorted insertion and added distructor