fixed metadata location bug
general refactoring