Added error checks
Added metadata handling
Added log option