sort
sorts and cleaned up code