Refactor student/book query