added optional metadata logging

+ cleanup