Added more tests and fixed one bug revealed in metadata removal