added a recursive version of sort