refactoring the logic to the book factory