Revert "Revert pull request #3466"

This reverts commit 59e3cae4c9c6f2c95a816a8280b470ec6add9486.
Fix for 500 error (undefined) in annotation tool