First round of metadata tests and some bug fixes