refactored book sort