Sort now working correctly

Sort fixed however need to remove tempfile and fix output problems