Reduced scope of some variables and replaced format_string with new one.