Cleaned up and fixed potential null pointers

This works on my machine, but there may be dependency issues. This patch adds a dependency on GSON, which I think was not there at the start.