decode json into a dict
move headers to variables list
add remove_old
simplify remove_old function