Added upgrade handling. Fixes #9