I think this can be really cleaned up by implementing a Metadata helper class in this file. This class has really large bloated methods and knows a lot about metadata. It would not need another file, but could be a subclass here for now.