JSON encoding compounds

+ some bug fixes