Fixed multiple bugs, some serious.
Also changed the structure of the JSON produced, so this is definitely a breaking change.