detect end of book