Complete refactoring of image annotation JS code