Implemented upgrade script closes #9

And optimize source code