Refactored autoupdate JS