Detecting player opening and closing writable book

Right so I'm trying to detect a player opening and closing a writable book. Ideally I'd like to be able to do both but only detecting the closing would be ok.

Currently I have a scoreboard and advancement system set up to track when the used:writable_book scoreboard increases. I check every tick with an advancement if it's larger than my dummy scoreboard and if it is run the command and increase the dummy by 1 bringing them back to equal.

The problem I have is that it usally detects on closing the book but sometimes inexplicably it detects the opening instead. Does anyone know why this is?

Does anyone have any better solutions for detecting the opening and closing of a writable book?

Continue to help post