Updated solution, separated code with functions, added object to help initially extract code blocks and retrieve them after all the markdown was completed.