Moved md_init_ctx() calls around to minimize exit points