Moved metadata to struct
Somewhat improved error handling