Fixed upgrade code to work with automatic plugin updates