added metadata, fixed sorting and replication