Refactor and added tests for meta data extraction