Optimize core functions

Improve upgrade method
Improve table creation method
Make uninstall method a static function