Added bunch of null checks, fixed serialize function

The special case where the user already has the latest version was not
handled correctly, but it is now.

Also, the serialize function included the module wrapper function in the
storage, causing the deserialization to produce invalid module
functions. This has been fixed as well.
0.0.4