Fix serialization of metadata. Add ShaMap implementation (needs testing)