Refactored C code. Metadata picture is also returned now